/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 24/09/2011, 14:11:43
 */
package tsb.UI.Ventanas;

import java.applet.AudioClip;
import java.awt.Adjustable;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.geom.Line2D;
import java.io.File;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import tsb.UI.PanelArrastrar.BotonPersonalizado;
import tsb.UI.PanelArrastrar.LineaConexion;

import tsb.UI.PanelArrastrar.PanelPrincipalV2;
import tsb.UI.arbol.panelArbolo;
import tsb.gestores.GestorXml;
import tsb.reproductor.ClockLabel;
import tsb.xml.LectorXML;

/**
 *
 * @author Fede
 */
public class Principal extends javax.swing.JFrame {
    
    private tsb.UI.PanelArrastrar.PanelPrincipalV2 panelPrincipalV2;
    private boolean banderaGestor= false;
    private boolean banderaGestorDispositivos= false;
    private tsb.gestores.GestorGrafo gestorGra;
    private tsb.gestores.GestorDeDispositivos gestorDisp;
    private tsb.gestores.GestorXml gestorXML;
    
    private int tipoDeConeccion;
    

    /** Creates new form Principal */
    public Principal()
    {
//        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//        this.setSize(screenSize); 
        
    
        initComponents();
        if (crearGestorGrafo()!= true)
        {
            JOptionPane.showMessageDialog(null,"Error al crear gestor Grafo");

        }
        else
        {
            banderaGestor=true;
        }

        if (crearGestorDispositivos()!= true)
        {
            JOptionPane.showMessageDialog(null,"Error al crear gestor Dispositivo");

        }
        else
        {
            banderaGestorDispositivos=true;
        }
        
        this.gestorXML = new GestorXml(gestorGra);

        
        //para maximizar
        this.setExtendedState(Principal.MAXIMIZED_BOTH);
        
        //Agregar el panel para arratras
        panelPrincipalV2 = new tsb.UI.PanelArrastrar.PanelPrincipalV2(this,gestorGra,gestorDisp);
         javax.swing.GroupLayout panelPrincipalV2Layout = new javax.swing.GroupLayout(panelPrincipalV2);
        panelPrincipalV2.setLayout(panelPrincipalV2Layout);
        panelPrincipalV2Layout.setHorizontalGroup(
            panelPrincipalV2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 864, Short.MAX_VALUE)
        );
        panelPrincipalV2Layout.setVerticalGroup(
            panelPrincipalV2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 448, Short.MAX_VALUE)
        );

        ScrollPanelArrastrar.setViewportView(panelPrincipalV2);
        
        //Listener para eventos de scroll del panel de arratrar
        AdjustmentListener listener = new MyAdjustmentListener();
        ScrollPanelArrastrar.getHorizontalScrollBar().addAdjustmentListener(listener);
        ScrollPanelArrastrar.getVerticalScrollBar().addAdjustmentListener(listener);

        // LLamar al metodo del reloj que coloca el reloj en el panel inferior
      // setRelojEnPanelInferior();
    }
    //*Gestor Grafo-------------------------------------------------
    public boolean crearGestorGrafo()
    {
       gestorGra= new tsb.gestores.GestorGrafo();
       if(gestorGra==null)
       {
           return false;
       }
       else
       {
            return true;
       }
    }
    public void setGestorGrafo(tsb.gestores.GestorGrafo gestor)
    {
        this.gestorGra=gestor;
    }
    public tsb.gestores.GestorGrafo getGestorGrafo()
    {
        return gestorGra;
    }
    //*-------------------------------------------------
    //*Gestor Dispositivos -------------------------------------------------
     public boolean crearGestorDispositivos()
    {
       gestorDisp= new tsb.gestores.GestorDeDispositivos(gestorGra);
       if(gestorDisp==null)
       {
           return false;
       }
       else
       {
            return true;
       }
    }
    public void setGestorDispositivos(tsb.gestores.GestorDeDispositivos gestor)
    {
        this.gestorDisp=gestor;
    }
    public tsb.gestores.GestorDeDispositivos getGestorDispositivos()
    {
        return gestorDisp;
    }
    //*-------------------------------------------------



    public PanelPrincipalV2 getPanelPrincipalV2() {
        return panelPrincipalV2;
    }

    public void setPanelPrincipalV2(PanelPrincipalV2 panelPrincipalV2) {
        this.panelPrincipalV2 = panelPrincipalV2;
    }

    public panelArbolo getPanelArbolo() {
        return panelArbolo;
       
    }

    public void setPanelArbolo(panelArbolo panelArbolo1) {
        this.panelArbolo = panelArbolo1;
       
    }

    
    

    

        @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelSuperior = new javax.swing.JPanel();
        btnGuardarXML = new javax.swing.JToggleButton();
        btnAbrirXML1 = new javax.swing.JToggleButton();
        panelDispositivos = new javax.swing.JPanel();
        panelConecciones = new javax.swing.JPanel();
        btnRJ45 = new javax.swing.JToggleButton();
        btnFibraOptica = new javax.swing.JToggleButton();
        btnSerialDTE = new javax.swing.JToggleButton();
        btnSerialDCE = new javax.swing.JToggleButton();
        btnAutomatica = new javax.swing.JToggleButton();
        btnAgregarPC = new javax.swing.JToggleButton();
        btnAgregarRouter = new javax.swing.JToggleButton();
        btnAgregarSwitch = new javax.swing.JToggleButton();
        btneliminar = new javax.swing.JToggleButton();
        btnAgregarModem = new javax.swing.JToggleButton();
        btnAgregarServer = new javax.swing.JToggleButton();
        panelInferior = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        ScrollPanelArrastrar = new javax.swing.JScrollPane();
        panelArbolo = new tsb.UI.arbol.panelArbolo();
        menuPrincipal = new javax.swing.JMenuBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Simulador de Redes");

        panelSuperior.setBackground(new java.awt.Color(255, 255, 255));
        panelSuperior.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        btnGuardarXML.setBackground(new java.awt.Color(255, 255, 255));
        btnGuardarXML.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/xml16x16.png"))); // NOI18N
        btnGuardarXML.setText("Guardar XML");
        btnGuardarXML.setName("agregarPC"); // NOI18N
        btnGuardarXML.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarXMLActionPerformed(evt);
            }
        });

        btnAbrirXML1.setBackground(new java.awt.Color(255, 255, 255));
        btnAbrirXML1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/xml16x16.png"))); // NOI18N
        btnAbrirXML1.setText("Abrir XML");
        btnAbrirXML1.setName("agregarPC"); // NOI18N
        btnAbrirXML1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAbrirXML1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelSuperiorLayout = new javax.swing.GroupLayout(panelSuperior);
        panelSuperior.setLayout(panelSuperiorLayout);
        panelSuperiorLayout.setHorizontalGroup(
            panelSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelSuperiorLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnAbrirXML1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnGuardarXML)
                .addContainerGap(922, Short.MAX_VALUE))
        );
        panelSuperiorLayout.setVerticalGroup(
            panelSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelSuperiorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAbrirXML1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnGuardarXML, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelDispositivos.setBackground(new java.awt.Color(255, 255, 255));
        panelDispositivos.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        panelConecciones.setBackground(new java.awt.Color(255, 255, 255));
        panelConecciones.setBorder(javax.swing.BorderFactory.createTitledBorder("Conecciones"));

        btnRJ45.setBackground(java.awt.Color.white);
        btnRJ45.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/CONEXION_RJ45_16x16.png"))); // NOI18N
        btnRJ45.setText("RJ45");
        btnRJ45.setName("rj45"); // NOI18N
        btnRJ45.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRJ45ActionPerformed(evt);
            }
        });

        btnFibraOptica.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/CONEXION_FIBRA_16x16.png"))); // NOI18N
        btnFibraOptica.setText("Fibra Óptica");
        btnFibraOptica.setName("fibraOptica"); // NOI18N
        btnFibraOptica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFibraOpticaActionPerformed(evt);
            }
        });

        btnSerialDTE.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/CONEXION_SERIAL_DTE_16x16.png"))); // NOI18N
        btnSerialDTE.setText("Serial DTE");
        btnSerialDTE.setName("serialDTE"); // NOI18N
        btnSerialDTE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSerialDTEActionPerformed(evt);
            }
        });

        btnSerialDCE.setBackground(new java.awt.Color(51, 255, 51));
        btnSerialDCE.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/CONEXION_SERIAL_DCE_16x16.png"))); // NOI18N
        btnSerialDCE.setText("Serial DCE");
        btnSerialDCE.setName("serialDCE"); // NOI18N
        btnSerialDCE.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSerialDCEActionPerformed(evt);
            }
        });

        btnAutomatica.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/CONEXION_AUTOMATICA_16x16.png"))); // NOI18N
        btnAutomatica.setText("Automatica");
        btnAutomatica.setName("Automatica"); // NOI18N
        btnAutomatica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAutomaticaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelConeccionesLayout = new javax.swing.GroupLayout(panelConecciones);
        panelConecciones.setLayout(panelConeccionesLayout);
        panelConeccionesLayout.setHorizontalGroup(
            panelConeccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConeccionesLayout.createSequentialGroup()
                .addGroup(panelConeccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnSerialDCE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnAutomatica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnSerialDTE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnRJ45, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnFibraOptica, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        panelConeccionesLayout.setVerticalGroup(
            panelConeccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConeccionesLayout.createSequentialGroup()
                .addComponent(btnRJ45)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnFibraOptica)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSerialDTE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSerialDCE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAutomatica))
        );

        btnAgregarPC.setBackground(new java.awt.Color(255, 255, 255));
        btnAgregarPC.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/PC_61x16.png"))); // NOI18N
        btnAgregarPC.setText("PC");
        btnAgregarPC.setName("agregarPC"); // NOI18N
        btnAgregarPC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarPCActionPerformed(evt);
            }
        });

        btnAgregarRouter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/ROUTER_16x16.png"))); // NOI18N
        btnAgregarRouter.setText("Router");
        btnAgregarRouter.setName("agregarRouter"); // NOI18N
        btnAgregarRouter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarRouterActionPerformed(evt);
            }
        });

        btnAgregarSwitch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/SWITCH_16x16.png"))); // NOI18N
        btnAgregarSwitch.setText("Switch");
        btnAgregarSwitch.setName("agregarSwitch"); // NOI18N
        btnAgregarSwitch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarSwitchActionPerformed(evt);
            }
        });

        btneliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/REMOVE_16x16.png"))); // NOI18N
        btneliminar.setText("Eliminar");
        btneliminar.setName("eliminar"); // NOI18N
        btneliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btneliminarActionPerformed(evt);
            }
        });

        btnAgregarModem.setBackground(new java.awt.Color(204, 0, 0));
        btnAgregarModem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/MODEM_16x16.png"))); // NOI18N
        btnAgregarModem.setText("Modem");
        btnAgregarModem.setActionCommand("Agregar Modem");
        btnAgregarModem.setBorder(null);
        btnAgregarModem.setBorderPainted(false);
        btnAgregarModem.setName("agregarModem"); // NOI18N
        btnAgregarModem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarModemActionPerformed(evt);
            }
        });

        btnAgregarServer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tsb/UI/Imagenes/SERVER_16x16.png"))); // NOI18N
        btnAgregarServer.setText("Server");
        btnAgregarServer.setName("agregarServer"); // NOI18N
        btnAgregarServer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnServerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelDispositivosLayout = new javax.swing.GroupLayout(panelDispositivos);
        panelDispositivos.setLayout(panelDispositivosLayout);
        panelDispositivosLayout.setHorizontalGroup(
            panelDispositivosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDispositivosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelDispositivosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelConecciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btneliminar)
                    .addGroup(panelDispositivosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btnAgregarModem, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAgregarServer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAgregarPC, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAgregarSwitch, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAgregarRouter, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelDispositivosLayout.setVerticalGroup(
            panelDispositivosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDispositivosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnAgregarPC)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAgregarRouter)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAgregarSwitch)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAgregarServer, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnAgregarModem, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(panelConecciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btneliminar)
                .addContainerGap(55, Short.MAX_VALUE))
        );

        panelInferior.setBackground(new java.awt.Color(255, 255, 255));
        panelInferior.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jButton1.setText("Mostrar Grafo");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelInferiorLayout = new javax.swing.GroupLayout(panelInferior);
        panelInferior.setLayout(panelInferiorLayout);
        panelInferiorLayout.setHorizontalGroup(
            panelInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelInferiorLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addContainerGap(1043, Short.MAX_VALUE))
        );
        panelInferiorLayout.setVerticalGroup(
            panelInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelInferiorLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jButton1)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        jSplitPane1.setDividerLocation(800);
        jSplitPane1.setLeftComponent(ScrollPanelArrastrar);
        jSplitPane1.setRightComponent(panelArbolo);

        setJMenuBar(menuPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelDispositivos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 983, Short.MAX_VALUE))
            .addComponent(panelInferior, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelSuperior, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelSuperior, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
                    .addComponent(panelDispositivos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelInferior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAgregarPCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarPCActionPerformed
       
        if(this.btnAgregarPC.isSelected())
        {//no esta seleccionado
            this.deshabilitarBotones(this.btnAgregarPC);
            this.panelPrincipalV2.setArratrarDispositivo(true);
            this.panelPrincipalV2.setAgregarDispositivo(PanelPrincipalV2.agregarPC);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPC);
        }
        else
        {//esta seleccionado
            this.habilitarBotones();
            this.panelPrincipalV2.setArratrarDispositivo(false);
            this.panelPrincipalV2.setAgregarDispositivo(0);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
        }
        
    }//GEN-LAST:event_btnAgregarPCActionPerformed

    private void btnAgregarRouterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarRouterActionPerformed
        
        if(this.btnAgregarRouter.isSelected())
        {//no esta seleccionado
            this.deshabilitarBotones(this.btnAgregarRouter);
            this.panelPrincipalV2.setArratrarDispositivo(true);
            this.panelPrincipalV2.setAgregarDispositivo(PanelPrincipalV2.agregarRouter);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorRouter);
            }
        else
        {//esta seleccionado
            this.habilitarBotones();
            this.panelPrincipalV2.setArratrarDispositivo(false);
            this.panelPrincipalV2.setAgregarDispositivo(0);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
        }
        
    }//GEN-LAST:event_btnAgregarRouterActionPerformed

    private void btnAgregarSwitchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarSwitchActionPerformed

        if(this.btnAgregarSwitch.isSelected())
        {//no esta seleccionado
            this.deshabilitarBotones(this.btnAgregarSwitch);
            this.panelPrincipalV2.setArratrarDispositivo(true);
            this.panelPrincipalV2.setAgregarDispositivo(PanelPrincipalV2.agregarSwitch);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorSwicht);
            }
        else
        {//esta seleccionado
            this.habilitarBotones();
            this.panelPrincipalV2.setArratrarDispositivo(false);
            this.panelPrincipalV2.setAgregarDispositivo(0);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
        }
    }//GEN-LAST:event_btnAgregarSwitchActionPerformed

    private void btnRJ45ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRJ45ActionPerformed

        if(this.btnRJ45.isSelected()) {//no esta seleccionado
            this.deshabilitarBotones(this.btnRJ45);
            this.panelPrincipalV2.setSeEstaConectando(true);
            this.panelPrincipalV2.setTipoDeconeccion(LineaConexion.ethernetRJ45);
        }
        else
        {
            this.habilitarBotones();
            this.panelPrincipalV2.setSeEstaConectando(false);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
            
        }
    }//GEN-LAST:event_btnRJ45ActionPerformed

private void btnFibraOpticaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFibraOpticaActionPerformed
   
    if(this.btnFibraOptica.isSelected()) {// esta seleccionado
            this.deshabilitarBotones(this.btnFibraOptica);
            this.panelPrincipalV2.setSeEstaConectando(true);
            this.panelPrincipalV2.setTipoDeconeccion(LineaConexion.fibra);
        }
        else
        {
            this.habilitarBotones();
            this.panelPrincipalV2.setSeEstaConectando(false);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
            
        }
}//GEN-LAST:event_btnFibraOpticaActionPerformed

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed

    if(this.btneliminar.isSelected())
    {
        this.deshabilitarBotones(btneliminar);
        this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorEliminar);
        this.panelPrincipalV2.setSeEstaEliminando(true);
    }
    else
    {
       this.habilitarBotones();
       this.panelPrincipalV2.setSeEstaEliminando(false);
       this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
       
    }
    
//    this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorEliminar);
//    this.panelPrincipalV2.setSeEstaEliminando(true);
}//GEN-LAST:event_btneliminarActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    System.out.print(gestorGra.toStringGrafo());
    
}//GEN-LAST:event_jButton1ActionPerformed

private void btnSerialDTEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSerialDTEActionPerformed
 
    if(this.btnSerialDTE.isSelected()) {//no esta seleccionado
            this.deshabilitarBotones(this.btnSerialDTE);
            this.panelPrincipalV2.setSeEstaConectando(true);
            this.panelPrincipalV2.setTipoDeconeccion(LineaConexion.serialDTE);
        }
        else
        {
            this.habilitarBotones();
            this.panelPrincipalV2.setSeEstaConectando(false);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
            
        }
}//GEN-LAST:event_btnSerialDTEActionPerformed

private void btnSerialDCEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSerialDCEActionPerformed
 
    if(this.btnSerialDCE.isSelected()) {//no esta seleccionado
            this.deshabilitarBotones(this.btnSerialDCE);
            this.panelPrincipalV2.setSeEstaConectando(true);
            this.panelPrincipalV2.setTipoDeconeccion(LineaConexion.serialDCE);
        }
        else
        {
            this.habilitarBotones();
            this.panelPrincipalV2.setSeEstaConectando(false);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
            
        }
}//GEN-LAST:event_btnSerialDCEActionPerformed

private void btnAutomaticaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAutomaticaActionPerformed
    if(this.btnAutomatica.isSelected()) {//no esta seleccionado
            this.deshabilitarBotones(this.btnAutomatica);
            this.panelPrincipalV2.setSeEstaConectando(true);
            this.panelPrincipalV2.setTipoDeconeccion(LineaConexion.automatica);
        }
        else
        {
            this.habilitarBotones();
            this.panelPrincipalV2.setSeEstaConectando(false);
            this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
            
        }
}//GEN-LAST:event_btnAutomaticaActionPerformed

private void btnServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnServerActionPerformed
 if(this.btnAgregarServer.isSelected())
       {//no esta seleccionado
           this.deshabilitarBotones(this.btnAgregarServer);
           this.panelPrincipalV2.setArratrarDispositivo(true);
           this.panelPrincipalV2.setAgregarDispositivo(PanelPrincipalV2.agregarServer);
           this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorServer);
           
       }
       else
       {//esta seleccionado
           this.habilitarBotones();
           this.panelPrincipalV2.setArratrarDispositivo(false);
           this.panelPrincipalV2.setAgregarDispositivo(0);
           this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
       }
// if(this.btnAgregarServer.isSelected())
//       {//no esta seleccionado
//           this.deshabilitarBotones(this.btnAgregarServer);
//           this.panelPrincipalV2.setArratrarDispositivo(true);
//           this.panelPrincipalV2.setAgregarDispositivo(PanelPrincipalV2.agregarServer);
//           this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorServer);
//       }
//       else
//       {//esta seleccionado
//           this.habilitarBotones();
//           this.panelPrincipalV2.setArratrarDispositivo(false);
//           this.panelPrincipalV2.setAgregarDispositivo(0);
//           this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
//       }
// 
    
    
    
}//GEN-LAST:event_btnServerActionPerformed

private void btnAgregarModemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarModemActionPerformed
   if(this.btnAgregarModem.isSelected())
       {//no esta seleccionado
           this.deshabilitarBotones(this.btnAgregarModem);
           this.panelPrincipalV2.setArratrarDispositivo(true);
           this.panelPrincipalV2.setAgregarDispositivo(PanelPrincipalV2.agregarModem);
           this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorModem);
       }
       else
       {//esta seleccionado
           this.habilitarBotones();
           this.panelPrincipalV2.setArratrarDispositivo(false);
           this.panelPrincipalV2.setAgregarDispositivo(0);
           this.panelPrincipalV2.setCursor(PanelPrincipalV2.cursorPredeterminado);
       }

}//GEN-LAST:event_btnAgregarModemActionPerformed

private void btnAbrirXML1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAbrirXML1ActionPerformed
    abrirFileChooser("abrir");
}//GEN-LAST:event_btnAbrirXML1ActionPerformed

private void btnGuardarXMLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarXMLActionPerformed
///    abrirFileChooser("grabar");
    String direccion="C:\\";
    this.gestorXML.grabarXML(direccion);
}//GEN-LAST:event_btnGuardarXMLActionPerformed

//public void dibujarLinea()
//{
//    Point ini = new Point(100,200);
//    Point fin = new Point(400,400);
//    Graphics2D g2d = ( Graphics2D ) getGraphics();
//
//    g2d.setPaint( new Color(0, 255, 0));//verde
//
// 
//    float guiones[] = { 1 };
//        g2d.setStroke( new BasicStroke( 3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5, guiones, 0 ) );
//        g2d.draw( new Line2D.Double( ini.x, ini.y, fin.x, fin.y ) );
//    
//}

private void abrirFileChooser(String aux)
{
    if(aux.compareTo("abrir")==0)
    {
       // mostrar cuadro de diálogo de archivo, para que el usuario pueda elegir el archivo a abrir
      JFileChooser selectorArchivo = new JFileChooser();
      //selectorArchivo.showOpenDialog(this);
      selectorArchivo.setFileSelectionMode( JFileChooser.FILES_ONLY );

      int resultado = selectorArchivo.showOpenDialog( this );

      // si el usuario hizo clic en el botón Cancelar del cuadro de diálogo, regresar
      if ( resultado == JFileChooser.CANCEL_OPTION )
      {
          System.out.print("cancele");
          return;
      }

        String ruta= selectorArchivo.getSelectedFile().getAbsolutePath().toString();

        System.out.println("Absolute Path: "+ruta);
        this.gestorXML.setUbicacionDocumento(ruta);
        LectorXML lector = new LectorXML(this.gestorGra);
        lector.procesarFichero(ruta);


      // fin de instrucción else
    }
    if(aux.compareTo("grabar")==0)
    {
          // mostrar cuadro de diálogo de archivo, para que el usuario pueda elegir el archivo a abrir
      JFileChooser selectorArchivo = new JFileChooser();
      selectorArchivo.setFileSelectionMode( JFileChooser.FILES_ONLY );

      int resultado = selectorArchivo.showSaveDialog( this );

      // si el usuario hizo clic en el botón Cancelar del cuadro de diálogo, regresar
      if ( resultado == JFileChooser.CANCEL_OPTION )
      {
        
          return;
      }

       this.gestorXML.grabarXML("C:\\");
      

      } // fin de instrucción else
  }
  

    
    
    /**
     * Se le pasa el botone que se esta precionando y se dehabilitan los demas
     * @param Boton que se esta presionando.
     */
    private void deshabilitarBotones(javax.swing.JToggleButton b)
    {
        String nombre= b.getName();
        
        if(nombre.compareTo("agregarPC")==0)
        {
            this.btnAgregarPC.setEnabled(true);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(false);
            return;
        }
        
        if(nombre.compareTo("agregarRouter")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(true);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(false);
            return;
        }
        
        if(nombre.compareTo("agregarSwitch")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(true);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(false);
            return;
        }
        
         if(nombre.compareTo("agregarServer")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(true);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(false);
            return;
        }
         //agregarModem
         
         if(nombre.compareTo("agregarModem")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(true);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            
            return;
        }
        
        
        
        if(nombre.compareTo("fibraOptica")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(true);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(false);
            return;
        }
        
        if(nombre.compareTo("rj45")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(true);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(false);
            return;
        }
        
        if(nombre.compareTo("serialDTE")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(true);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(false);
            return;
        }


        if(nombre.compareTo("serialDCE")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(true);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            return;
        }
        
        if(nombre.compareTo("Automatica")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(true);
            
            this.btneliminar.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            return;
        }
        
        if(nombre.compareTo("eliminar")==0)
        {
            this.btnAgregarPC.setEnabled(false);
            this.btnAgregarRouter.setEnabled(false);
            this.btnAgregarSwitch.setEnabled(false);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            
            this.btnFibraOptica.setEnabled(false);
            this.btnRJ45.setEnabled(false);
            this.btnSerialDCE.setEnabled(false);
            this.btnSerialDTE.setEnabled(false);
            this.btnAutomatica.setEnabled(false);
            
            this.btneliminar.setEnabled(true);
            this.btnAgregarServer.setEnabled(false);
            this.btnAgregarModem.setEnabled(false);
            return;
        }

        
        
          
          
    }
    
        public void habilitarBotones()
    {

        //habilitar los botones
        this.btnAgregarPC.setEnabled(true);
        this.btnAgregarRouter.setEnabled(true);
        this.btnAgregarSwitch.setEnabled(true);
        this.btnAgregarServer.setEnabled(true);
        this.btnAgregarModem.setEnabled(true);
        
        this.btnFibraOptica.setEnabled(true);
        this.btnRJ45.setEnabled(true);
        this.btneliminar.setEnabled(true);
        this.btnSerialDCE.setEnabled(true);
        this.btnSerialDTE.setEnabled(true);
        this.btnAutomatica.setEnabled(true);
        this.btnAgregarServer.setEnabled(true);
        this.btnAgregarModem.setEnabled(true);
            
        //deseleccioner los botones            
            this.btnAgregarPC.setSelected(false);
            this.btnAgregarRouter.setSelected(false);
            this.btnAgregarSwitch.setSelected(false);
            this.btnAgregarServer.setSelected(false);
            this.btnAgregarModem.setSelected(false);
            
            this.btnFibraOptica.setSelected(false);
            this.btnRJ45.setSelected(false);
            this.btneliminar.setSelected(false);
            this.btnSerialDCE.setSelected(false);
            this.btnSerialDTE.setSelected(false);
            this.btnAutomatica.setSelected(false);
            

          
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane ScrollPanelArrastrar;
    private javax.swing.JToggleButton btnAbrirXML1;
    private javax.swing.JToggleButton btnAgregarModem;
    private javax.swing.JToggleButton btnAgregarPC;
    private javax.swing.JToggleButton btnAgregarRouter;
    private javax.swing.JToggleButton btnAgregarServer;
    private javax.swing.JToggleButton btnAgregarSwitch;
    private javax.swing.JToggleButton btnAutomatica;
    private javax.swing.JToggleButton btnFibraOptica;
    private javax.swing.JToggleButton btnGuardarXML;
    private javax.swing.JToggleButton btnRJ45;
    private javax.swing.JToggleButton btnSerialDCE;
    private javax.swing.JToggleButton btnSerialDTE;
    private javax.swing.JToggleButton btneliminar;
    private javax.swing.JButton jButton1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JMenuBar menuPrincipal;
    private tsb.UI.arbol.panelArbolo panelArbolo;
    private javax.swing.JPanel panelConecciones;
    private javax.swing.JPanel panelDispositivos;
    private javax.swing.JPanel panelInferior;
    private javax.swing.JPanel panelSuperior;
    // End of variables declaration//GEN-END:variables

    private boolean ban=false;

    
    
    
    //Clase que maneja los eventos de scroll del panel de arratrado para que cresca el panel
    class MyAdjustmentListener implements AdjustmentListener {
    public void adjustmentValueChanged(AdjustmentEvent evt) {
        Adjustable source = evt.getAdjustable();
        
         if (evt.getValueIsAdjusting()==false)
         {
             if((source.getValue()+source.getVisibleAmount())== source.getMaximum())
             {
                  Dimension area= panelPrincipalV2.getArea();
                   // Determine which scrollbar fired the event
                   int orient = source.getOrientation();
                   if (orient == Adjustable.HORIZONTAL) {
                       // Event from horizontal scrollbar
                       
                        area.width = area.width+50;
                        panelPrincipalV2.setPreferredSize(area);
                        panelPrincipalV2.revalidate();
                        ScrollPanelArrastrar.getHorizontalScrollBar().setValue(ScrollPanelArrastrar.getHorizontalScrollBar().getMaximum());
                   } else {
                       area.height = area.height+50;
                       panelPrincipalV2.setPreferredSize(area);
                       panelPrincipalV2.revalidate();
                       ScrollPanelArrastrar.getVerticalScrollBar().setValue(ScrollPanelArrastrar.getVerticalScrollBar().getMaximum());
                   }
             }
         }
    }
    }
     static int contadorPC=0;
     static int contadorRouter=0;
     static int contadorSwitch=0;
     static int contadorServer=0;
     static int contadorModem=0;

    public static String getNombreDispositivos(int tipoDispositivo)
    {
        switch(tipoDispositivo)
        {
            case 1://PC
                String pc="PC-";
                contadorPC++;
                return pc+contadorPC;

            case 2://Router
                String router="Router-";
                contadorRouter++;
                return router+contadorRouter;

            case 3://switch
                String switc="Switch-";
                contadorSwitch++;
                return switc+contadorSwitch;

            case 4://Server
                String server="Server-";
                contadorServer++;
                return server+contadorServer;

            case 5://Modem
                String modem="Modem-";
                contadorModem++;
                return modem+contadorModem;

        }
        return "";

    }
    
}


